/***************************************************************************************************
  Copyright(C)   2011-8-24
  All rights reserved.
  File Name: routedb.h

  Description:数据库模块
              操作数据库之前要先 打开数据库 ,如果只需得到播放内容列表，如需调用getCustomPlayPkgList()
              口就行了,想要打开别的数据库或者关闭程序之前请先 关闭数据库，也提供了一系列的设置内容和删除的接口,
              详细请看各个函数介绍,具体涉及到的结构体可以在environment.h文件看查看
              其中假期播放方式 playMode:1,优先 2,最后 3,插入

  ***************************************************************************************************/

#ifndef ROUTEDB_H
#define ROUTEDB_H

#include <QDate>

#include "database.h"
#include "environment.h"

//查询错误信息
typedef enum {
    NOERR,                  //0 无错误

    //下面3个是警告，查找不到内容或者查找不到分区
    LOSTCONTENTWARIN,            //1 有内容包但无配置播放内容(根据contentID找不到相对应的播放内容)
    LOSTLAYOUTWARIN,             //2 有内容包但无配置播放布局(播放内容找不相对应的播放布局)
    LOSTLAYCNTWARIN,             //3 有内容包但无配置布局和内容


    DIRECTEIDERR,           //4  查找不到列车方向ID
    ROUTEIDERR,             //5  查找不到ROUTEID
    STATIONIDERR,           //6  查找不到stationID
    STATUSIDERR,            //7  查找不到列车状态ID(statusID)
    USEPKGERR,              //8  查找不到用户包ID(pkgID)--8
    DEFAULTERR,             //9  查找不到默认包ID(defaultID)
    PKGRELATERR,            //10 查找不到包内容
    LAYOUTERR,              //11 查找不到布局
    NOPLAYLISTERR,          //12 查找不到播放列表内容
}PLAYPKGERR;



class RouteDB
{
public:
    RouteDB();

    ~RouteDB();

    void setResourcePath(const QString& resource);
    bool openDB(const QString& DBPath);
    bool closeDB();

    bool isOpen();

    //得到自定义播放包列表 RoutePkgStruct:播放包结构体
    PLAYPKGERR getCustomPlayPkgList(QList<RoutePkgList>& routePkgList, const RouteMsgStruct& routeMsgStruct) const;
    //得到默认播放包列表
    PLAYPKGERR getDefaultPlayPkgList(QList<RoutePkgList>& routePkgList, const RouteMsgStruct& routeMsgStruct) const;

    //
    PLAYPKGERR getCePlayPkgList(QList<RoutePkgList>& routePkgList, const CeRouteMsg& routeMsgStruct) const;

    PLAYPKGERR getCeDefaultPlayPkgList(QList<RoutePkgList>& routePkgList, const CeRouteMsg& routeMsgStruct) const;


    //设置表内容接口
    bool setMainRelatTableCnt(const MainRelatIDStruct& mainRelatIDStruct) const;
    bool setLayoutTableCnt(const LayoutStruct& layoutStruct) const;
    bool setPkgRelatTableCnt(const PkgRelatStruct& pkgRelatStruct) const;
    bool setPkgDesTableCnt(const PkgDesStruct& pkgDesStruct) const;
    bool setHoliCntRelatTableCnt(const ContentStruct& holidayCntStruct) const;
    bool setHoliCntDesTableCnt(const HoliDesStruct& holiDesStruct) const;
    bool setPlayModeTableCnt(const HoliPlayModStruct& holiPlayModStruct) const;
    bool setUsrCntRelatTableCnt(const ContentStruct& usrContentStruct) const;
    bool setUsrCntDesTableCnt(const UsrCntDesStruct& usrCntDesStruct) const;
    bool setUsrCntTypeTableCnt(UsrCntTypeStruct usrCntTypestruct) const;

    bool setUsrInfo(const UsrInfoStru usrInfoStruct) const;
    bool setHolidayInfo(const HoliInfoStruct holidayInfoStruct) const;


    //删除内容接口
    bool delMainRelatTableCnt(const MainRelatIDStruct& mainRelatIDStruct) const;
    bool delLayoutTableCnt(const int layoutID, const int partitionID) const;
    bool delPkgRelatTableCnt(const int packageID) const;
    bool delPkgDesTableCnt(const int packageID) const;
    bool delHoliCntRelatTableCnt(const int holidayContentID, const QString& holiday) const;
    bool delHoliCntDesTableCnt(const int contentID) const;
    bool delPlayModeTableCnt(const int playModeID) const;
    bool delUsrCntRelatTableCnt(const int contentID) const;
    bool delUsrCntDesTableCnt(const int contentID) const;
    bool delUsrCntTypeTableCnt(const int contentTypeID) const;


private:
    DataBase DB;
    bool dbIsOPen;

private:
    QList<ContentStruct> sortOnlyUsrCntList(const QList<UsrInfoStru>& usrInfoStructList) const;

    QList<ContentStruct> sortHoliAndUsrCntList(const QList<UsrInfoStru> &usrInfoStructList,
                                          const QList<HoliInfoStruct> &holiInfoStructList) const;


};

#endif // ROUTEDB_H
